//
//  LDYStatus.swift
//  李东阳微博
//
//  Created by 李东阳 on 16/4/20.
//  Copyright © 2016年 李东阳. All rights reserved.
//

import UIKit

class LDYStatus: NSObject {

    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    /// 用户模型
    var user:LDYUserInfo?
    /// 转发微博
    var retweeted_status:LDYStatus?
     /// LDYPicInfo
     var pic_urls:[LDYPicInfo]?
    // 转发数
    var reposts_count: Int = 0
    // 评论数
    var comments_count: Int = 0
    // 表态数
    var attitudes_count: Int = 0
    
    
    
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
            //MARK: -  
        
        if key == "user"{
        
            if let v = value as?[String:AnyObject]{
            
            let u = LDYUserInfo(dict: v )
                
               user = u
              
            }
            
        }else if key == "retweeted_status"{
        
            if let v = value as? [String:AnyObject]{
            
            let u = LDYStatus(dict: v)
                
            retweeted_status = u 
            }
            
        }else if key == "pic_urls" {
            
                //MARK: -  定义一个临时数组
            var temArray:[LDYPicInfo] = [LDYPicInfo]()
            
            if let array = value as? [[String: AnyObject]]{
            
                "TODO:|FIXME:value是一个数组  需要遍历解析 "
                for dict in array{
                    
                 let picInfo = LDYPicInfo(dict: dict)
                    
                  temArray.append(picInfo)
                    
                }
                pic_urls = temArray
            }
        
        }
        
        else{
              super.setValue(value, forKey: key)
            }
       

    }
    
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
